package 牛客题霸;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class 在两个长度相等的排序数组中找到上中位数 {

    public static int findMedianinTwoSortedAray(int[] arr1, int[] arr2) {
        if (arr1.length <= 0 && arr2.length <= 0) {
            return 0;
        }
        int arr1Index = 0;
        int arr2Index = 0;
        int index = 0;
        int[] temp = new int[arr1.length + arr2.length];
        while (arr1Index < arr1.length && arr2Index < arr2.length) {
            if (arr1[arr1Index] <= arr2[arr2Index]) {
                temp[index++] = arr1[arr1Index++];
            } else {
                temp[index++] = arr2[arr2Index++];
            }
        }
        while (arr1Index < arr1.length) {
            temp[index++] = arr1[arr1Index++];
        }
        while (arr2Index < arr2.length) {
            temp[index++] = arr1[arr2Index++];
        }
        return temp[((arr1.length + arr2.length) / 2) - 1];
    }

    public static void main(String[] args) {

    }
}
